Basically, I'm creating a command line program that performs a Caesar Cypher using the entire ASCII table. Now I can get it to encrypt, but it doesn't decrypt for some reason.
I'm not really sure if this conditional statement is correct, so that might be the issue.
Code:
if ((argc == 4) && (argv[1] == "-d")){
i = 1;
offset = 2;
printf("About to encrypt file...\n");
inFile = fopen(argv[2], "r");
outFile = fopen(argv[3], "w");
printf("The files have been opened.\n");
if (inFile == NULL) {
printf("Unable to open %s\n", argv[2]);
exit(1);
}
if (outFile == NULL) {
printf("Could not open %s\n", argv[3]);
exit(1);
}
while ((current = fgetc(inFile)) != EOF){
printf("Scanning file %s\n", argv[2]);
printf("Printing decrypted %c to %s\n", current, argv[3]);
nRep = (int)current;
if (nRep - (offset + i) < 0) nRep = (128 + (nRep - (offset + i)));
else nRep = (nRep - (i + offset));
current = (char)nRep;
fprintf(outFile, "%c", current);
i++;
}
fclose(inFile);
fclose(outFile);
}
Now I had a debug statement in my program to display what argv[1] was, and it would show -d. Yet, the encryption function would still get satisfied somehow and it would encrypt the already encrypted file instead.
Any help would be greatly appreciated